<?php
$q=$_GET["q"];
$hint="";
if(strlen($q)>0)
{
include_once ("Login/databaseconnection.php");
require_once ("Login/config.php");
$tex="";
$sql_s ="SELECT DISTINCT(Congeniality) FROM school";
$result_s = mysql_query($sql_s);
while($row_s = mysql_fetch_array($result_s))
{
if(empty($tex))
{
$con=$row_s['Congeniality'];
$tex="Number of ".$con." schools in Zones";
}
else
{
$con=$row_s['Congeniality'];
$tex=$tex.",Number of ".$con." schools in Zones";
}
}

$sql_Ethi ="SELECT DISTINCT(Ethinicity) FROM school";
$result_Ethi = mysql_query($sql_Ethi);
while($row_Ethi = mysql_fetch_array($result_Ethi))
{
if(empty($tex))
{
$Ethi=$row_Ethi['Ethinicity'];
$tex="Number of ".$Ethi." schools in Zones";
}
else
{
$Ethi=$row_Ethi['Ethinicity'];
$tex=$tex.",Number of ".$Ethi." schools in Zones";
}
}

$sql_Fun ="SELECT DISTINCT(Function) FROM school";
$result_Fun = mysql_query($sql_Fun);
while($row_Fun = mysql_fetch_array($result_Fun))
{
if(empty($tex))
{
$Fun=$row_Fun['Function'];
$tex="Number of ".$Fun." schools in Zones";
}
else
{
$Fun=$row_Fun['Function'];
$tex=$tex.",Number of ".$Fun." schools in Zones";
}
}

$sql ="SELECT DISTINCT(Resource_Type) FROM resource";
$resulttable = mysql_query($sql);
while ($row = mysql_fetch_array($resulttable))
{
if(empty($tex))
{
$r=$row['Resource_Type'];
$tex="Number of ".$r." in labs";
}
else
{
$r=$row['Resource_Type'];
$tex=$tex.",Number of ".$r." in labs";
}
}

$sqls ="SELECT  DISTINCT(Appointed_Subject) FROM teacher";
$results = mysql_query($sqls);
while ($rows = mysql_fetch_array($results))
{
if(empty($tex))
{
$s=$rows['Appointed_Subject'];
$tex="Number of ".$s." teachers in Schools";
}
else
{
$s=$rows['Appointed_Subject'];
$tex=$tex.",Number of ".$s." teachers in Schools";
}
}
$sqlsp ="SELECT DISTINCT(Specialised_In) FROM teacher";
$resultsp = mysql_query($sqlsp);
while ($rowsp = mysql_fetch_array($resultsp))
{
if(empty($tex))
{
$sp=$rowsp['Specialised_In'];
$tex="Number of ".$sp." specialised teachers in Schools";
}
else
{
$sp=$rowsp['Specialised_In'];
$tex=$tex.",Number of ".$sp." specialised teachers in Schools";
}
}
$sql_t ="SELECT DISTINCT(Training_Id) FROM training_details";
$result_t = mysql_query($sql_t);
while ($row_t = mysql_fetch_array($result_t))
{
if(empty($tex))
{
$t=$row_t['Training_Id'];
$tra_name=mysql_query("SELECT * FROM training WHERE Training_Id='".$t."'");
if($row_tra=mysql_fetch_array($tra_name))
{
$Training_Name=$row_tra['Training_Name'];
}
$tex="Number of ".$Training_Name." trained teachers in Schools";
}
else
{
$t=$row_t['Training_Id'];
$tra_name=mysql_query("SELECT * FROM training WHERE Training_Id='".$t."'");
if($row_tra=mysql_fetch_array($tra_name))
{
$Training_Name=$row_tra['Training_Name'];
}
$tex=$tex.",Number of ".$Training_Name." trained teachers in Schools";
}
}
$sql_lc ="SELECT DISTINCT(Lab_Category) FROM lab";
$result_lc = mysql_query($sql_lc);
while($row_lc = mysql_fetch_array($result_lc))
{
if(empty($tex))
{
$lc=$row_lc['Lab_Category'];
$tex="Number of ".$lc." labs in Schools";
}
else
{
$lc=$row_lc['Lab_Category'];
$tex=$tex.",Number of ".$lc." labs in Schools";
}
}

$sql_lt ="SELECT DISTINCT(Lab_Type) FROM lab";
$result_lt = mysql_query($sql_lt);
while($row_lt = mysql_fetch_array($result_lt))
{
if(empty($tex))
{
$lt=$row_lt['Lab_Type'];
$tex="Number of ".$lt."s in Schools";
}
else
{
$lt=$row_lt['Lab_Type'];
$tex=$tex.",Number of ".$lt."s in Schools";
}
}

$tex=$tex.",Number of Labs,Number of Students in Schools,Number of Teachers in Schools,Number of Students for Programmes,Number of Trained Teachers for Programmes,Number of Teachers in Training for Programmes,Service period of teachers,Training duration of trained teachers,Won times of Competitions";

$hin=explode(",",$tex);
for($i=0;$i<count($hin);$i++)
{
$value=substr($hin[$i],0,strlen($q));
if(strcasecmp($value,$q)==0)
{
$column=$hin[$i];
if($arr=="")
{
$arr=$column;
}
else
{
$arr=$arr.",".$column;
}
}
}
 $array= explode(",",$arr);
if(count($array)>5)
{
 $hint=$hint.'<div style="height:200px; width:438px; overflow-Y:scroll; ">';
}
for ($i = 0; $i <count($array); $i++) 
{
 $temp =$array[$i];
  if($temp!="")
  {
  $hint=$hint.'<li onClick="filladv(\''.$temp.'\');">'.$temp.'</li>';
  }
  $j = $i;
  for ($k = 0; $k <count($array); $k++) 
  {
    if ($k != $j) {
      if ($temp == $array[$k]) 
	  {
        $array[$k]="";
      }
    }
  }
}
if(count($array)>5)
{
   $hint=$hint.'</div>';
}
}
if($hint=="")
{
$response="No suggestions";
}
else
{
$response=$hint;
}
echo $response;
?>